<?php
//declare and assigne variables
$update_bugID = $_POST['bugToUpdate'];

$previous_pri = $_POST['oldPriority'];
$update_pri = $_POST['updatePri'];

$update_status = $_POST['updateStatus'];
$previous_status = $_POST['oldStatus'];

$update_date = $_POST['updateDateClosed'];

$update_assignee = $_POST['updateAssignee'];
$previous_assignee = $_POST['oldAssignee'];

$update_owner= $_POST['updateOwner'];
$previous_owner = $_POST['oldOwner'];

//Leave comment: 1- "no" 2 - "yes"
$comment_submitted = $_POST['inputComment'];
$comment_text = $_POST['comments'];
$comment_name = $_POST['commentSubmitter'];
$comment_date = $_POST['commentDate'];

//Connect to database
require_once('database2.php');

//Test is updates have changed from current values
if ($update_pri == "0"){
	$update_pri = $previous_pri;
}

if ($update_status == "0"){
	$update_status = $previous_status;
}

if ($update_assignee == "0"){
	$update_assignee = $previous_assignee;
}

if ($update_owner == "0"){
	$update_owner = $previous_owner;
}

//Form query for BugMaster table
$query = "UPDATE BugMaster
			SET Priority = '$update_pri', Status = '$update_status', Assignee = '$update_assignee', DateClosed = '$update_date', Owner = '$update_owner'
			WHERE bugID = '$update_bugID'";
			
			
//If Comments Submitted for MySQL insert command and commit
if ($comment_submitted == "2"){
$comQuery = "INSERT INTO CommentMaster
			(bugID, employeeID, Text, date)
			 VALUES
			('$update_bugID', '$comment_name', '$comment_text', '$comment_date')"; 

$db->exec($comQuery);

}

//Execute BugMaster query			
$db->exec($query);		


//Return to buglist			
include('buglist.php');
?>